<?php

require_once('firePHP/fb.php');

 /**
  * FirePHP LoggerAppender for log4php.
  *
  * <p>Appends log events to the FirePHP Firefox Extension.</p>
  * <p>The data can be displayed in the Firebug Console or in the
  * "Server" request tab.</p>
  *
  * <p>For more information see: http://www.firephp.org/</p>
  *
  * <p>Attention: PHP 5 >= 5.2.0 version required.</p>
  *
  * @author Gayaz Yusipov <gzep at vingrad dot ru>
  * @package log4php
  * @subpackage appenders
  */

 class LoggerAppenderFirePHP extends LoggerAppender {

     private
         /**
          * Wildfire protocol message index.
          *
          * @var integer
          * @access private
          */
         $index = 1,

         /**
          * Comparison of event types.
          * <p>Keys are {@link LoggerLevel}, values are FirePHP levels.</p>
          *
          * @var array
          * @access private
          */
         $types = array(
             'TRACE' => 'LOG',
             'DEBUG' => 'LOG',
             'INFO' => 'INFO',
             'WARN' => 'WARN',
             'ERROR' => 'ERROR',
             'FATAL' => 'ERROR'
         );

     public function __construct($name = "") {
            parent::__construct($name);
            $this->requiresLayout = true;

     }

     public function __destruct() {

         $this->close();

     }

     public function activateOptions() {

         $this->closed = false;

     }

     public function close() {

         $this->closed = true;

     }

     public function append(LoggerLoggingEvent $event) {
            
            
                     
           $level = $event->getLevel();
		   $tl = strtolower($level->toString());
                    
           if(is_object($event->getMessage()))
                $message = $event->getMessage();
           else
                $message = $this->layout->format($event);/**/
                       
			switch($tl) {
				case 'debug':
                    FB::log($message);
					break;
				case 'info':
                    FB::info($message);
					break;
				case 'warn':
                    FB::warn($message);
					break;
				case 'error':
                    FB::error($message);
					break;
				case 'fatal':
                    FB::error($message);
					break;
				default:
                    FB::log($message);
			}/**/
     }

  }

 ?>